package cn.wzptsoft.tinymallbe.controller;

import cn.wzptsoft.common.utils.Result;
import cn.wzptsoft.tinymallbe.entity.Theme;
import cn.wzptsoft.tinymallbe.service.ThemeService;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("theme")
public class ThemeController {
    private final ThemeService themeService;

    public ThemeController(ThemeService themeService) {
        this.themeService = themeService;
    }

    /**
     * 获取一组专题
     *
     * @param names 专题名称 以逗号分割
     * @return 专题信息
     */
    @GetMapping("/by/names")
    public Result<List<Theme>> getThemeByNames(@RequestParam(name = "names") String names) {
        List<String> nameList = Arrays.asList(names.split(","));
        List<Theme> themes = themeService.findByNames(nameList);
        return Result.ok(themes);
    }

    /**
     * 获取某个专题的详情 含商品列表
     *
     * @param name 专题名称
     * @return 专题详情
     */
    @GetMapping("/detail/{name}")
    public Result<Theme> getThemeByNameWithSpu(@PathVariable(name = "name") String name) {
        Theme theme = themeService.findByName(name);
        return Result.ok(theme);
    }
}
